﻿using System;
using System.Windows;

namespace Dsl.Ped.Framework.Common
{
    /// <summary>
    /// General implementation of the projection hint
    /// </summary>
    /// <typeparam name="T">Type of the projection represented by the hint</typeparam>
    public class ProjectionHint<T> : IProjectionHint<T>
        where T : FrameworkElement, new()
    {
        #region Fields

        /// <summary>
        /// Default configuration of the hint. Default configuration is applied first after the instance of 
        /// <see cref="T"/> is created
        /// </summary>
        private Action<T, Type> defaultConfiguration;

        /// <summary>
        /// Custom configuration of the hint. Custom configuration is applied after the <see cref="defaultConfiguration"/>
        /// </summary>
        private Action<T> customConfigurations; 

        #endregion

        #region Members

        /// <summary>
        /// Gets the type of the projection
        /// </summary>
        public Type ProjectionType 
        { 
            get { return typeof(T); } 
        }

        /// <summary>
        /// Gets or sets the <see cref="defaultConfiguration"/> of the projection
        /// </summary>
        public Action<T, Type> DefaultConfiguration
        {
            get
            {
                return defaultConfiguration;
            }
            private set
            {
                defaultConfiguration = value;
            }
        }

        /// <summary>
        /// Gets or sets the <see cref="customConfiguration"/> of the projection
        /// </summary>
        public Action<T> CustomConfiguration
        {
            get
            {
                return this.customConfigurations;
            }
            private set
            {
                this.customConfigurations = value;
            }
        }

        /// <summary>
        /// Gets the <see cref="DependencyProperty"/> representing the value to which the bindings into
        /// the projection of type <see cref="T"/> can be created
        /// </summary>
        public DependencyProperty ValueProperty { get; private set; }

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectionHint{T}"/> class.
        /// </summary>
        /// <param name="defaultConfiguration">The default configuration</param>
        /// <param name="customConfiguration">The custom configuration</param>
        public ProjectionHint(Action<T, Type> defaultConfiguration, Action<T> customConfiguration)
        {
            this.DefaultConfiguration = defaultConfiguration;
            this.CustomConfiguration = customConfiguration;
        }
    }
}
